package cuiyt.juc.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author cyt
 * @create 2020-05-01 17:27
 */
public class demo01 {
    // 创建线程的三个方法
    public static void main(String[] args) {
        // 创建固定大小的线程池
        ExecutorService service = Executors.newFixedThreadPool(3);
        // 创建一个缓存的线程池， 大小可变
        ExecutorService service1 = Executors.newCachedThreadPool();
        // 创建一个单一的线程池
        ExecutorService service2 = Executors.newSingleThreadExecutor();
        try {
            for (int i = 1; i <= 5; i++) {
                service2.execute(() -> {
                    System.out.println(Thread.currentThread().getName());
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            service2.shutdown();
        }
    }
}
